//
//  LTM_PopBaseView.m
//  LTM_Inherit_PopView_Objc
//
//  Created by 柯南 on 2021/11/25.
//

#import "LTM_PopBaseView.h"

#import <Masonry/Masonry.h>

@interface LTM_PopBaseView ()
/// 取消
@property (nonatomic, strong) UIButton *cancelBtn;
/// 标题
@property (nonatomic, strong) UILabel *titleLabel;
/// 确认
@property (nonatomic, strong) UIButton *sureBtn;
/// 分割线
@property (nonatomic, strong) UIView *dividerView;
/// 弹框内容父视图
@property (nonatomic, strong) UIView *popBgView;
@end

@implementation LTM_PopBaseView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];

    if (self) {
        self.layer.cornerRadius = 15;
        self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
        [self addSubview:self.popBgView];
        [self addSubview:self.dividerView];
        [self addSubview:self.cancelBtn];
        [self addSubview:self.titleLabel];
        [self addSubview:self.sureBtn];
        [self.popBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(self);
        }];
        [self.dividerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.popBgView.mas_top);
            make.left.right.equalTo(self);
            make.height.mas_equalTo(1);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(20);
            make.centerX.equalTo(self);
            make.bottom.equalTo(self.dividerView.mas_top).offset(-20);
        }];
        [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(@[self.titleLabel,self.sureBtn]);
            make.left.equalTo(self).offset(28);
        }];
        [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-28);
        }];
    }
    return self;
}

#pragma mark - Set

- (void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = _title;
}

#pragma mark - Event
- (void)cancelBtnClick{
    if (self.popCancelBlock) {
        self.popCancelBlock();
    }
}

- (void)sureBtnClick{
    
}
#pragma mark - UILazy
- (UIButton *)cancelBtn{
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_cancelBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    }
    
    return _cancelBtn;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:16];
    }
    
    return _titleLabel;
}

- (UIButton *)sureBtn{
    if (!_sureBtn) {
        _sureBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_sureBtn setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [_sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    }
    
    return _sureBtn;
}

- (UIView *)dividerView{
    if (!_dividerView) {
        _dividerView = [[UIView alloc]init];
        _dividerView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.05];
    }
    
    return _dividerView;
}

- (UIView *)popBgView{
    if (!_popBgView) {
        _popBgView = [[UIView alloc] init];
    }
    
    return _popBgView;
}


@end
